home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / srgploca.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  14.8 KB  |  553 lines

  1.  
  2. /** IMPORTANT INFORMATION FOR MACINTOSH DEVELOPERS/ADMINISTRATORS
  3. The source code for the Macintosh version of SRGP uses conditional compilation
  4. to support both the original QuickDraw and Color QuickDraw.
  5. You must edit the file "ChooseWhichQuickDraw.h"; see instructions therein.
  6. **/
  7.  
  8. #ifdef X11
  9. #include <X11/Xlib.h>
  10. #include <X11/Xutil.h>
  11. #include <X11/Xos.h>
  12. #include <X11/cursorfont.h>
  13. #ifdef sun
  14. #include <malloc.h>
  15. #else
  16. extern char *malloc();
  17. #endif
  18. #endif
  19.  
  20. #ifdef GRX
  21. #include <grx.h>
  22. #include <mousex.h>
  23. #include <malloc.h>
  24. #endif
  25.  
  26. #define point            srgp__point
  27. #define rectangle        srgp__rectangle
  28. #define attribute_group  srgp__attribute_group
  29.  
  30. #define REPORT_ERROR   SRGP__error
  31. #define NON_FATAL 0
  32. #define FATAL     1
  33.  
  34. #include "macros.h"
  35.  
  36. #include "srgp_sphigs.h"
  37.  
  38. #include "srgppublic.h"
  39. #include "srgp_errtypes.h"
  40. #include "assert.h"
  41.  
  42.  
  43.  
  44.  
  45. #ifdef SRGP_BOSS
  46. #define DECLARE
  47. boolean srgp__traceDisabled=TRUE;
  48. boolean srgp__userDebugAidsDisabled=FALSE;
  49. boolean srgp__enabled=FALSE;
  50. boolean srgp__blockedWaitEnabled=FALSE;
  51. #else
  52. #define DECLARE extern
  53. extern boolean srgp__traceDisabled;
  54. extern boolean srgp__userDebugAidsDisabled;
  55. extern boolean srgp__enabled;
  56. extern boolean srgp__blockedWaitEnabled;
  57. #endif
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. /** THE CANVAS DATABASE
  67. Each canvas is described with a "canvas_spec" record, containing
  68. the dimensions of the canvas, the current value of all the
  69. attributes (stored in a group), and the vdi bitmap index.
  70.  
  71. When canvas X becomes active, a copy of the database spec for X
  72. is put into the global variable "current_active_canvas_spec".
  73. This global's fields are changed
  74. as activity occurs as long as X remains
  75. active; the database spec's fields therefore becomes obsolete.
  76. When canvas X becomes inactive, the global's value is copied
  77. into the database spec for X, thus updating the database, correcting
  78. the temporary obsolescence.
  79. **/
  80.  
  81. #ifdef X11
  82.    typedef union {
  83.       XID       xid;     /* FOR ANY CANVAS */
  84.       Window    win;     /* ONLY FOR 0th CANVAS */
  85.       Pixmap    bitmap;  /* FOR ALL OTHER CANVASES */
  86.    }
  87.    drawable_type;
  88. #endif
  89.  
  90. #ifdef THINK_C
  91. typedef void *grafptr;
  92.    typedef union {
  93.       grafptr    xid;     /* FOR ANY CANVAS */
  94.       WindowPtr  win;     /* ONLY FOR 0th CANVAS */
  95.       grafptr    bitmap;  /* FOR ALL OTHER CANVASES */
  96.    }
  97.    drawable_type;
  98. #endif
  99.  
  100. #ifdef GRX
  101.    typedef union {
  102.       GrContext *xid;     /* FOR ANY CANVAS */
  103.       GrContext *win;     /* ONLY FOR 0th CANVAS */
  104.       GrContext *bitmap;  /* FOR ALL OTHER CANVASES */
  105.    }
  106.    drawable_type;
  107. #endif
  108.  
  109. #define srgpx__screenwin                (srgp__canvasTable[0].drawable.win)
  110.  
  111.  
  112. typedef struct {
  113.    int                  max_xcoord, max_ycoord;
  114.    attribute_group      attributes;
  115.    drawable_type        drawable;
  116. #ifdef X11
  117.    GC           gc_frame, gc_fill;
  118. #endif
  119. #ifdef THINK_C
  120.    int     transfermode_frame, transfermode_fill;
  121.    Pattern *pat_frame, *pat_fill;
  122. #endif
  123. #ifdef GRX
  124.    union {
  125.         int fc;                 /* color for SOLID */
  126.         GrPattern *fp;          /* pattern for ???_PATTERN */
  127.         long val;               /* argument for GRX primitive */
  128.    } grx_fill_data;
  129.    union {
  130.         int lc;                 /* color for SOLID, continuous */
  131.         GrLineOption  *lo;      /* dash patt for SOLID, DASHED .. */
  132.         GrLinePattern *lp;      /* pattern for ??_PATTERN */
  133.         long val;               /* argument for GRX primitives */
  134.    } grx_pen_data;
  135.    enum {
  136.         GRX_fill_solid = 0,     /* use 'GrFilled...' group */
  137.         GRX_fill_patterned      /* use 'GrPatternFilled...' group */
  138.    } grx_fill_style;
  139.    enum {
  140.         GRX_pen_solid = 0,      /* use 'GrLine', etc .. */
  141.         GRX_pen_dashed,         /* use 'GrCustom...' group */
  142.         GRX_pen_patterned       /* use 'GrPatterned...' group */
  143.    } grx_pen_style;
  144.    GrContext grx_canvas;        /* GRX context */
  145.    GrPattern grx_penpatt;       /* drawing pen fill pattern */
  146.    GrPattern grx_fillpatt;      /* solid fill pattern */
  147.    GrLineOption  grx_lineopt;   /* GRX dashed line option */
  148.    GrLinePattern grx_linepatt;  /* GRX dashed line draw pattern */
  149.    GrTextOption  grx_textopt;   /* GRX text drawing option */
  150. #endif
  151. }
  152. canvas_spec;
  153.  
  154. DECLARE int             srgp__curActiveCanvasId;
  155. DECLARE canvas_spec     srgp__curActiveCanvasSpec;
  156. DECLARE canvas_spec     *srgp__canvasTable;
  157.  
  158. void SRGP__setCanvasDefaults (void);
  159. void SRGP__reactToScreenResize (int newwidth, int newheight);
  160. void SRGP__forceScreenResize (int newwidth, int newheight);
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /** THE PATTERN DATABASES
  167. In X11:  Each pattern index maps into a pointer to an X Pixmap.
  168. In Mac:  bitpats and pixpats will have to be quite different!
  169. **/
  170.  
  171. #ifdef X11
  172. typedef Pixmap                  pattern_table_entry, pixpat_table_entry;
  173. #endif
  174.  
  175. #ifdef THINK_C
  176. typedef Pattern                 pattern_table_entry;
  177. typedef PixPatHandle            pixpat_table_entry;
  178. #endif
  179.  
  180. #ifdef GRX
  181. typedef GrPattern               *pixpat_table_entry;
  182. typedef unsigned char           *pattern_table_entry;
  183. #endif
  184.  
  185.  
  186. DECLARE pattern_table_entry     *srgp__bitmapPatternTable;
  187. DECLARE pixpat_table_entry      *srgp__pixmapPatternTable;
  188.  
  189. extern void SRGP__initDefaultPatterns (void);
  190.  
  191.  
  192.  
  193.  
  194. /** THE CURSOR DATABASE
  195. Each entry maps to a cursor resource.
  196. **/
  197.  
  198. #ifdef X11
  199.    typedef Cursor       cursorInfo;
  200. #endif
  201.  
  202. #ifdef THINK_C
  203.    typedef CursHandle   cursorInfo;
  204. #endif
  205.  
  206. #ifdef GRX
  207.    typedef GrCursor    *cursorInfo;
  208. #endif
  209.  
  210. DECLARE cursorInfo      *srgp__cursorTable;
  211.  
  212. extern void SRGP__initCursorTable (void);
  213.  
  214.  
  215.  
  216.  
  217. /** THE FONT DATABASE
  218. X11: A fontInfo item that is NULL represents an unused entry.
  219. Mac: txFont number -1 represents an unused entry.
  220. Initially, only one entry (the one indexed 0) is used.
  221. **/
  222.  
  223. #ifdef X11
  224.    typedef XFontStruct                  *fontInfo;
  225.  
  226. /* ultrix ifdef added by pausch */
  227. #ifdef ultrix
  228. #define SRGP_DEFAULT_FONT_0             "terminal14"
  229. #else
  230. #define SRGP_DEFAULT_FONT_0             "8x13"
  231. #endif
  232.  
  233. #endif
  234.  
  235. #ifdef THINK_C
  236.    typedef struct {
  237.       int txFont, txSize;
  238.       Style txFace;
  239.    } fontInfo;
  240. #endif
  241.  
  242. #ifdef GRX
  243.    typedef GrFont                       *fontInfo;
  244. #  define  SRGP_DEFAULT_FONT_0          "@:pc8x14.fnt"
  245. #endif
  246.  
  247. DECLARE fontInfo        *srgp__fontTable;
  248.  
  249. void SRGP__initFont (void);
  250.  
  251.  
  252.  
  253.  
  254. /** INPUT
  255. **/
  256.  
  257. /* locator measure */
  258. DECLARE srgp__deluxe_locator_measure
  259.                 srgp__cur_locator_measure, srgp__get_locator_measure;
  260. DECLARE int srgp__cur_Xcursor_x, srgp__cur_Xcursor_y;   /* IN X/Mac COORDS */
  261. DECLARE int     srgp__cur_locator_button_mask;
  262.  
  263. DECLARE boolean srgp__dirty_location;
  264. /* "dirty" bool is used only when: 1) in sample mode and 2) rubber echo off */
  265.  
  266. /* locator echo */
  267. DECLARE int             srgp__cur_locator_echo_type;
  268. DECLARE srgp__point     srgp__cur_locator_echo_anchor;
  269. DECLARE int             srgp__cur_cursor;
  270.  
  271. /* keyboard measure */
  272. DECLARE srgp__deluxe_keyboard_measure
  273.                 srgp__cur_keyboard_measure,
  274.                 srgp__get_keyboard_measure;
  275. DECLARE int     srgp__cur_keyboard_measure_length;  /* not buffer length! */
  276. DECLARE int     srgp__cur_keyboard_processing_mode;
  277.  
  278. /* keyboard echo */
  279. DECLARE int             srgp__cur_keyboard_echo_font;
  280. DECLARE int             srgp__cur_keyboard_echo_color;
  281. DECLARE srgp__point     srgp__cur_keyboard_echo_origin;
  282.  
  283. /* TIMESTAMP FOR EVENT THAT IS SUBJECT TO GET */
  284. DECLARE int srgp__get_timestamp;
  285.  
  286. DECLARE int srgp__cur_mode[4];   /* one for each device, including NO_DEVICE */
  287. DECLARE int srgp__device_at_head_of_queue;
  288.  
  289. void    SRGP__initInputModule (void);
  290. void    SRGP__initInputDrivers (void);
  291. void    SRGP__activateDevice (int device);
  292. void    SRGP__deactivateDevice (int device);
  293. int     SRGP__handleRawEvents (boolean in_waitEvent_call, boolean forever);
  294. void    SRGP__initEchoModule (void);
  295. void    SRGP__enableLocatorRubberEcho (void);
  296. void    SRGP__disableLocatorRubberEcho (void);
  297. void    SRGP__updateLocatorRubberEcho (void);
  298. void    SRGP__updateLocatorRubberAnchor (void);
  299. void    SRGP__enableLocatorCursorEcho (void);
  300. void    SRGP__disableLocatorCursorEcho (void);
  301. void    SRGP__updateLocatorCursorShape (void);
  302. void    SRGP__updateRawCursorPosition (void);
  303. void    SRGP__enableKeyboardEcho (void);
  304. void    SRGP__disableKeyboardEcho (void);
  305. void    SRGP__updateKeyboardEcho (void);
  306. void    SRGP__updateKeyboardEchoAttributes (void);
  307.  
  308.  
  309.  
  310.  
  311. /** MARKERS **/
  312.  
  313. void SRGP__drawSquareMarker (int x, int y);
  314. void SRGP__drawCircleMarker (int x, int y);
  315. void SRGP__drawXMarker (int x, int y);
  316.  
  317.  
  318. /** ERRORS **/
  319. #ifdef THINK_C
  320. void ReportSpecialError (char *message, boolean is_fatal);
  321.  
  322. /* We hide this from gnu's compiler, which doesn't understand it. */
  323. void SRGP__error (int errtype, ...);
  324. #endif
  325.  
  326. extern errorHandlingMode srgp__curErrHndlMode;
  327.  
  328.  
  329. /** COLOR **/
  330. DECLARE int             srgp__available_depth;    /* usually 8 or 1 */
  331. DECLARE unsigned long   srgp__max_pixel_value;    /* based on avail_depth */
  332. DECLARE int             srgp__application_depth;  /* specified by appl */
  333. DECLARE int             srgp__base_colorindex;    /* explained in color_X11.c */
  334.  
  335. #ifdef X11
  336. DECLARE int             srgp__visual_class;
  337. #define XBLACK          BlackPixel(srgpx__display,srgpx__screen)
  338. #define XWHITE          WhitePixel(srgpx__display,srgpx__screen)
  339. #define XCOLOR(I)       (I == 0 ? XWHITE : (I == 1 ? XBLACK : I))
  340.  
  341. #define COLORINDEX(c) \
  342.     ( (unsigned long)(c) | (unsigned long)srgp__base_colorindex )
  343. #endif
  344.  
  345. #ifdef THINK_C
  346. #define COLORINDEX(c)   ((int)(c|srgp__base_colorindex))
  347. #endif
  348.  
  349. #ifdef GRX
  350. DECLARE int             *srgp__color_lookup_table;
  351. #define COLORINDEX(c)   (srgp__color_lookup_table[c])
  352. #endif
  353.  
  354.  
  355. void SRGP__initColor (int requested_planes);
  356. void SRGP__cleanupColor (void);
  357. void SRGP__activateApplColorTable (void);
  358. void SRGP__deactivateApplColorTable (void);
  359.  
  360.  
  361.  
  362. /** LOW-LEVEL GRAPHICS **/
  363. void SRGP__initGraphicsDevice
  364.    (char *name, int requested_planes, boolean debugasap);
  365. void SRGP__cleanupMacMemory (void);
  366.  
  367.  
  368. /** STORAGE OF VERTEX LISTS
  369. Needed by the X version of output.c
  370. **/
  371. #ifdef X11
  372. DECLARE XPoint *Xformat_vertices;
  373. #endif
  374.  
  375.  
  376. #ifdef THINK_C
  377. /** MAC UTILITIES **/
  378. Rect FIXED_RECT (int lx, int by, int rx, int ty);
  379. #endif
  380.  
  381.  
  382. DECLARE funcptr         srgp__resizeCallback;
  383.  
  384.  
  385. #ifdef X11
  386. DECLARE Display        *srgpx__display;
  387. DECLARE int             srgpx__screen;
  388. DECLARE Colormap        srgpx__colormap;
  389. #endif
  390.  
  391.  
  392. #ifdef THINK_C
  393. DECLARE WindowPtr       srgpmac__cwindow;
  394. DECLARE MenuHandle      srgpmac__applemenu, srgpmac__srgpmenu;
  395. #define Time   long
  396. #endif
  397.  
  398.  
  399. /** TIMESTAMPS **/
  400.  
  401. #ifdef X11
  402. #define rawgranularity  1000  /* per second */
  403. #endif
  404.  
  405. #ifdef THINK_C
  406. #define rawgranularity 60 /* per second */
  407. #endif
  408.  
  409. #ifdef GRX
  410. #define Time   long
  411. #define rawgranularity 18.2 /* per second */
  412. #endif
  413.  
  414.  
  415. DECLARE Time            srgpx__starttime, srgpx__cur_time;
  416.  
  417. #undef DECLARE
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429. /** TRACING AND DEBUGGING MACROS
  430. **/
  431.  
  432. #define DEBUG_AIDS      if(!srgp__userDebugAidsDisabled)
  433.  
  434. #define SRGP_trace      if(!srgp__traceDisabled)fprintf
  435.  
  436. #define LeaveIfNonFatalErr()   \
  437.    if(SRGP_errorOccurred)return
  438.  
  439. #define srgp_check_system_state()       \
  440.    if(!srgp__enabled)  SRGP__error(ERR_NOT_ENABLED)
  441.  
  442. #define srgp_check_rectangle(LX, BY, RX, TY)            \
  443.    if(!((LX<=RX)&&(BY<=TY)))  SRGP__error(ERR_BAD_RECT, LX, BY, RX, TY)
  444.  
  445. #define srgp_check_font_index(F)        \
  446.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)))   \
  447.       SRGP__error(ERR_BAD_FONT_INDEX,F)
  448.  
  449. #ifdef X11
  450. #define srgp_check_extant_font(F)       \
  451.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)&&(srgp__fontTable[F])))     \
  452.       SRGP__error(ERR_UNKNOWN_FONT,F)
  453. #endif
  454.  
  455. #ifdef GRX
  456. #define srgp_check_extant_font(F)       \
  457.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)&&(srgp__fontTable[F])))     \
  458.       SRGP__error(ERR_UNKNOWN_FONT,F)
  459. #endif
  460.  
  461. #ifdef THINK_C
  462. #define srgp_check_extant_font(F)       \
  463.    if(!((F>=0)&&(F<=MAX_FONT_INDEX)&&(srgp__fontTable[F].txFont!=(-1))))        \
  464.       SRGP__error(ERR_UNKNOWN_FONT,F)
  465. #endif
  466.  
  467. #define srgp_check_poly_item_count(C)   \
  468.    if(!(F>0))  SRGP__error(ERR_BAD_POLY_ITEM_COUNT,C)
  469.  
  470. #define srgp_check_marker_style(MS)             \
  471.    if(!((MS>=0)&&(MS<NUMBER_OF_MARKER_STYLES)))  \
  472.       SRGP__error(ERR_BAD_MARKER_STYLE,MS)
  473.  
  474. #define srgp_check_marker_size(MS)              \
  475.    if(!(MS>0))\
  476.       SRGP__error(ERR_BAD_MARKER_SIZE,MS)
  477.  
  478. #define srgp_check_line_style(LS)               \
  479.    if(!((LS>=CONTINUOUS)&&(LS<=DOT_DASHED)))  \
  480.       SRGP__error(ERR_BAD_LINE_STYLE,LS)
  481.  
  482. #define srgp_check_line_width(LW)               \
  483.    if(!(LW>0))\
  484.       SRGP__error(ERR_BAD_LINE_WIDTH,LW)
  485.  
  486. #define srgp_check_write_mode(WM)               \
  487.    if(!((WM>=WRITE_REPLACE)&&(WM<=WRITE_AND)))\
  488.       SRGP__error(ERR_BAD_WRITE_MODE,WM)
  489.  
  490. #define SRGP_correct_color(C)           \
  491.    if(C>srgp__max_pixel_value) \
  492.       C = srgp__max_pixel_value;
  493.  
  494. #define srgp_check_pixel_value(C,STR)           \
  495.    if(C>srgp__max_pixel_value) \
  496.       SRGP__error(ERR_BAD_PIXEL_VALUE,STR,C)
  497.  
  498. #define srgp_check_fill_style(F)        \
  499.    if(!((F>=SOLID)&&(F<=BITMAP_PATTERN_OPAQUE)))\
  500.       SRGP__error(ERR_BAD_FILL_STYLE,F)
  501.  
  502. #define srgp_check_pattern_table_entry(E) \
  503.    if(E==0) SRGP__error(ERR_BAD_PATTERN_TABLE_ENTRY)
  504.  
  505. #define srgp_check_pattern_index(P)     \
  506.    if(!((P>=0)&&(P<=MAX_PATTERN_INDEX)))  SRGP__error(ERR_BAD_PATTERN_ID,P)
  507.  
  508. #define srgp_check_cursor_index(P)      \
  509.    if(!((P>=0)&&(P<=MAX_CURSOR_INDEX)))  SRGP__error(ERR_BAD_CURSOR_ID,P)
  510.  
  511. #define srgp_check_extant_canvas(CV)    \
  512.    if(!(((CV>=0)||(CV<=MAX_CANVAS_INDEX))&&\
  513.         (srgp__canvasTable[CV].drawable.bitmap)))\
  514.       SRGP__error(ERR_CANVAS_NOT_OPEN,CV)
  515.  
  516. #define srgp_check_device(D)    \
  517.    if(!((D>=KEYBOARD)&&(D<=LOCATOR)))  SRGP__error(ERR_BAD_DEVICE,D)
  518.  
  519. #define srgp_check_mode(D)      \
  520.    if(!((D>=INACTIVE)&&(D<=EVENT)))  SRGP__error(ERR_BAD_MODE,D)
  521.  
  522. #define srgp_check_polygon_list_size(D) \
  523.    if((D<3)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  524.  
  525. #define srgp_check_polymarker_list_size(D)      \
  526.    if((D<0)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  527.  
  528. #define srgp_check_polyline_list_size(D)        \
  529.    if((D<2)||(D>MAX_POINTLIST_SIZE))  SRGP__error(ERR_POINTLIST_SIZE,D)
  530.  
  531. #define srgp_check_event_type(EVTYP)  \
  532.    if(!(srgp__device_at_head_of_queue==EVTYP))  SRGP__error(ERR_BAD_GET)
  533.  
  534. #define srgp_check_locator_echo_type(MS)        \
  535.    if(!((MS>=NO_ECHO)&&(MS<=RUBBER_RECT))) \
  536.       SRGP__error(ERR_BAD_LOC_ECHO_TYPE,MS)
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543. /** MACROS
  544. **/
  545.  
  546. #define FIXED(yy)       \
  547.     (srgp__curActiveCanvasSpec.max_ycoord-(yy))
  548. #define SCREENFIXED(yy) \
  549.     (srgp__canvasTable[0].max_ycoord-(yy))
  550.  
  551. #define PUSH_TRACE       srgp__userDebugAidsDisabled++
  552. #define POP_TRACE        srgp__userDebugAidsDisabled--
  553.